package com.bwie.controller;

import com.bwie.pojo.Type;
import com.bwie.service.TypeService;
import com.bwie.service.impl.TypeServiceImpl;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

/**
 * 商品分类表(tb_type)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/brand/brand")
@Api(tags = "商品分类")
public class TypeController {
    /**
     * 服务对象
     */
    @Autowired
    private TypeService typeService;

    /**
     * @author: 鑫仔
     * @description: 下拉列表
     * @params: []
     * @return: com.bwie.utils.R
     * @date: 2025/7/21 14:22
     */
    @ApiOperation("列表")
    @PostMapping("getTypeTree")
    public R getTypeTree(
            @RequestBody PageInfoVo pageInfoVo
    ) {
        return typeService.getTypeTree(pageInfoVo);
    }

    /**
     * @author: 鑫仔
     * @description: 下拉框分类数据
     * @params: []
     * @return: com.bwie.utils.R
     * @date: 2025/7/22 16:28
     */
    @PostMapping("getSelectType")
    public R getSelectType() {
        return typeService.getSelectType();
    }

    /**
     * @author: 鑫仔
     * @description: 上传图片
     * @params: [org.springframework.web.multipart.MultipartFile]
     * @return: com.bwie.utils.R
     * @date: 2025/7/21 16:58
     */
    @ApiOperation("上传图片")
    @PostMapping("uploadFile")
    public R uploadFile(
            @RequestPart(value = "file") MultipartFile file
    ) {
        return typeService.uploadFile(file);
    }

    /**
     * @author: 鑫仔
     * @description: 添加分类
     * @params: [com.bwie.pojo.Type]
     * @return: com.bwie.utils.R
     * @date: 2025/7/21 17:25
     */
    @ApiOperation("添加分类")
    @PostMapping("addType")
    public R addType(
            @RequestBody @Validated Type type
    ) {
        return typeService.addType(type);
    }

}
